package es.dk.hl.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.facebook.commands.batch.BatchRun;
	import com.facebook.commands.data.SetObjectProperty;
	import com.facebook.data.batch.BatchCollection;
	import com.facebook.events.FacebookEvent;
	
	import es.dk.hl.model.HomeLinkModelLocator;

	/**
	 * 
	 * $facebook->api_client->data_createObject('composiciones','{"composicion":"[wall + taca + taca]"}');
	 * <data_createObject_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">5003336616809</data_createObject_response>
	 * 
	 * $facebook->api_client->data_defineAssociation('usercompo',1,'{"alias":"uid"}','{"alias":"composicion","type":"homelink.composiciones"}','');
	 * <?xml version="1.0" encoding="UTF-8"?>
	 * <data_defineAssociation_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1
	 * </data_defineAssociation_response>
	 * 
	 * $facebook->api_client->data_setAssociation('usercompo',1390854429,5003336616809,'','');
	 * <?xml version="1.0" encoding="UTF-8"?>
	 * <data_setAssociation_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1</data_setAssociation_response>
	 * 
	 * $facebook->api_client->data_getAssociatedObjects('usercompo',1390854429,1);
	 * <?xml version="1.0" encoding="UTF-8"?>
	 * <data_getAssociatedObjects_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true">
	 * <object_association>
	 * <id2>5003336616809</id2>
	 * <time>1256289488</time>
	 * </object_association>
	 * </data_getAssociatedObjects_response>
	 * 
	 * $facebook->api_client->data_getObject(5003336616809,'');
	 * <?xml version="1.0" encoding="UTF-8"?>
	 * <data_getObject_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true">
	 * <data_getObject_response_elt>2759077</data_getObject_response_elt>
	 * <data_getObject_response_elt>5003336616809</data_getObject_response_elt>
	 * <data_getObject_response_elt>[wall + taca + taca]</data_getObject_response_elt>
	 * </data_getObject_response>
	 * 
	 * $facebook->api_client->data_updateObject(5003336616809,'{"composicion"}','{"dsjflkdljsjfls"}');
	 * <?xml version="1.0" encoding="UTF-8"?>
	 * <data_updateObject_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1</data_updateObject_response>
	 *
	 * $facebook->api_client->data_removeAssociation('usercompo',1390854429,5003336616809);
	 * <?xml version="1.0" encoding="UTF-8"?>
	 * <data_removeAssociation_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1</data_removeAssociation_response>
	 * * 
	 */
	public class FaceBook_Save_Command implements ICommand
	{

		public function FaceBook_Save_Command()
		{
		}
		
		public function execute(event:CairngormEvent):void {
			//--> 1ºopcion = el updateOBject no estaá bien programado en la API
			//--> 2ºopcion = el removeassociation no lo hace bien, new FBEvent(FBEvent.FBEvent_DELETE).dispatch();
			//--> 3ºopcion = debería haber sido la 2º ya que funciona :) es hacer un SetObjectProperty
			var batch:BatchCollection = new BatchCollection();
			var o:Object = new Object();
			o["composicion"] = HomeLinkModelLocator.getInstance().composicion;
			batch.addItem(
				new SetObjectProperty(
					String(HomeLinkModelLocator.getInstance().composicion_id),
					"composicion",
					o["composicion"]))
			var batchRun:BatchRun = HomeLinkModelLocator.getInstance().facebook.post(new BatchRun(batch)) as BatchRun;
			batchRun.addEventListener(FacebookEvent.COMPLETE, onBatchComplete1);
		}
		
		protected function onBatchComplete1(event:FacebookEvent):void {
			if (event.success) {	
			}
		}	
	}
}